<?php
#                                                                                 
# author: Cody Sorgenfrey                                       
# (c)2013 South Hill Calvary Chapel                                               
#
function add_title($name) {
	$p = 'Pastor';
	$e = 'Elder';
	$m = 'Missionary';
	$c = 'Chaplain';
	$patterns = array("/Ron Sanchez/", "/Kasey Hanson/", "/Jason Sanchez/", "/Alan Chappell/", "/Phil Spagnolo/", "/Bob Caldwell/", "/Kevin Day/", "/Frank Boulet/", "/Kris Repp/", "/Joel Meyer/", "/Samy Tanagho/", "/Luis Vargas/", "/Fikret Bocek/", "/Ed Williams/", "/Charles Gillaspie/", "/Jason Murdock/", "/Brian Headrick/");
	$replacements = array($p." Ron Sanchez", $p." Kasey Hanson", $p." Jason Sanchez", $p." Alan Chappell", $p." Phil Spagnolo", $p." Bob Caldwell", $p." Kevin Day", $c." Frank Boulet", $m." Kris Repp", $m." Joel Meyer", $m." Samy Tanagho", $m." Luis Vargas", $m." Fikret Bocek", $e." Ed Williams", $p." Charles Gillaspie", $p." Jason Murdock", $p." Brian Headrick");
	
	return preg_replace($patterns, $replacements, $name);
}                                                                                 
include_once("../mysql/database_info.php");
include_once("../mysql/common.php");
connect_select_test("sermons");


header('Content-type: text/xml');
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');

echo "<rss xmlns:content='http://purl.org/rss/1.0/modules/content/' xmlns:wfw='http://wellformedweb.org/CommentAPI/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:sy='http://purl.org/rss/1.0/modules/syndication/' xmlns:slash='http://purl.org/rss/1.0/modules/slash/' xmlns:itunes=\"http://www.itunes.com/dtds/podcast-1.0.dtd\" version='2.0'>\n";
echo  "\t<channel>\n";
echo  "\t\t<author>South Hill Calvary Chapel</author>\n";
echo  "\t\t<title>South Hill Calvary Chapel ".ucfirst($_GET['service'])." Service</title>\n";
echo  "\t\t<link>http://www.southhillcalvary.org</link>\n";
echo  "\t\t<description>".ucfirst($_GET['service'])." service teachings at South Hill Calvary Chapel</description>\n";
echo  "\t\t<summary>".ucfirst($_GET['service'])." Bible teachings from South Hill Calvary Chapel</summary>\n";
echo  "\t\t<language>en-us</language>\n";
echo  "\t\t<category text=\"Religion &amp; Spirituality\"><category text=\"Christianity\"></category></category>\n";  
echo  "\t\t<image href=\"http://www.southhillcalvary.org/images/podcast.jpg\"></image>\n";

echo  "\t\t<itunes:author>South Hill Calvary Chapel</itunes:author>\n";
echo  "\t\t<itunes:summary>".ucfirst($_GET['service'])." service teachings at South Hill Calvary Chapel</itunes:summary>\n";
echo  "\t\t<itunes:image href=\"http://www.southhillcalvary.org/images/podcast.jpg\" />\n";

echo  "\t\t<explicit>clean</explicit>\n";    
$result = mysql_query("SELECT * FROM `sermons` WHERE `service`='".$_GET['service']."' ORDER BY `date` DESC LIMIT 0,50");
while ($sermon = mysql_fetch_array($result)){
	echo  "\t\t\t<item>\n";
	echo  "\t\t\t\t<title>".$sermon['title']."</title>\n";
	echo  "\t\t\t\t<subtitle>".add_title($sermon['name'])." shares from ".$sermon['book']." ".$sermon['verse']."</subtitle>\n";
	echo  "\t\t\t\t<pubDate>".date("r", strtotime($sermon['date']))."</pubDate>\n";
	echo  "\t\t\t\t<duration>01:00:00</duration>\n";
	echo  "\t\t\t\t<enclosure url=\"http://southhillcalvary.org".$sermon['file']."\" length=\"150MB\" type=\"audio/mpeg\"/>\n";
	echo  "\t\t\t\t<guid>".$sermon['id']."</guid>\n";
	echo  "\t\t\t\t\n";
	echo  "\t\t\t</item>\n";
}
echo  "\t</channel>\n";
echo  "</rss>\n";
?>
